#include <iostream>
#include "httplib.h"

void hello(const httplib::Request &req, httplib::Response &res)
{
    res.set_content("hellp World", "text/plain");
    res.status = 200;
}

void Numbers(const httplib::Request &req, httplib::Response &res)
{
    auto num = req.matches[1]; //0里面是整体的path，从1开始是新捕捉的路径
    res.set_content(num, "text/plain");
    res.status = 200;
}

void Multiparts(const httplib::Request &req, httplib::Response &res)
{
    auto ret = req.form.has_file("file");
    if(ret == false)
    {
        std::cout<< "NOT FILE UPLOAD! \n";
        res.status = 404;
        return;
    }
    const auto& file = req.form.get_file("file");
    res.body.clear();

    res.body += file.filename;
    res.body += "\n";  
    res.body += file.content;
    res.set_header("Content-Type","test/plain");
    res.status = 200;
    return;


}
int main()
{
    httplib::Server ser;
    ser.Get("/hi", hello);
    ser.Get(R"(/numbers/(\d+))", Numbers);
    ser.Post("/Multipart", Multiparts);
    ser.listen("0.0.0.0", 8080);
    return 0;
}
